import time
from web.models import User, Notice, GroupMember


def valid_login(username, password):
    data_dict = {
        "username": username,
        "password": password
    }
    user = User.objects.filter(**data_dict).first()
    if user:
        return True
    else:
        return False


def get_newid():
    time_now = int(time.time())
    # 转换成localtime
    time_local = time.localtime(time_now)
    # 转换成新的时间格式(2016-05-09 18:59:20)
    dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
    id = time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S"))
    return id


def del_notice(id):
    Notice.objects.filter(id=id).delete()


def get_user_by_keyword(keyword):
    # queryset
    user = User.objects.filter(username__icontains=keyword)
    return user


def toTF(num):
    if num == 1:
        return True
    return False
